<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>资源加载</title>
	</head>
	<body>
		<button onclick="getCss()">点我加载css，按钮变得好看啦</button>
		<button onclick="getHtml()">点我加载html</button>
		<button onclick="getJs()">点我加载javascript</button>
		<button onclick="getAll()">点我分别加载</button>
		<button onclick="getAll2()">点我一次性加载</button>
		<button onclick="getJs2()">点我a(b,c,d),b(c,d),c(d)</button>
		<button onclick="getPathsAndShim()">测试path和shim配置</button>
		<button onclick="getConfigs()">测试其他配置（超时时长为1秒）</button>
		<button onclick="getRedirect()">测试资源被dns重定向导致错误</button>
		<div id="html">
		</div>
		<script src="../src/loader.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			function getCss () {
				require(["css!../demo/css/button.css"],function(){
					console.log("第一个按钮的颜色变成粉色了。")
				})
			};
			function getHtml(){
				require(["text!../demo/modules/m1.html"],function(html){
					document.getElementById("html").innerHTML=html;
					console.log("添加了一段html。");
				})
			}
			function getJs(){
				require(["../demo/modules/m1.js"],function(js){
					js();
					console.log("脚本加载过来了。");
				})
			}
			function getAll () {
				getCss();
				getHtml();
				getJs();
			}
			function getAll2 () {
				require(["../demo/modules/m1.js","text!../demo/modules/m1.html","css!../demo/css/button.css"],function(js,html){
					document.getElementById("html").innerHTML=html;
					js();
					console.log("一次加载3个文件。");
				})
			}
			function getJs2 () {
				require(["../demo/modules/a.js"],function (js) {
					js();
					console.log("a,b,c,d全部加载完成。");
				});
			}
			require.config({
				paths:{
					"$":"https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js",
					jSlimscroll:"http://cdn.bootcss.com/jQuery-slimScroll/1.3.6/jquery.slimscroll.min.js"
				},
				shim:{
					"jSlimscroll":{
						deps:["$"],
						exports: 'jQuery.fn.slimScroll'
					}
				}
			});
			function getPathsAndShim () {
				require(["text!../demo/modules/scrollText.txt","jSlimscroll"],function(scHtml,scFunc){
					document.getElementById("html").innerHTML=scHtml;
			        scFunc.apply($("#inner-content"),{
			            height: '300px'
			        });
				})
			}
			function getConfigs () {
				require.config({
					waitSeconds: 1,
					loadStamp: "3.1415926",
					nocache: false,
					debug: true,
					urlCaseInsensitive: false,
			
					onStart: function(){
						alert("开始搞起。")
					},
					onComplete: function(){
						alert("不晓得对错，反正搞完的。")
					},
					onError: function(reload,end){
						if(confirm("加载失败，是否继续加载？")){
							reload();
						}else{
							end();
						}
					},
					onText: null
				});
				getPathsAndShim ()
			}
			function getRedirect () {
				require.config({
					debug:false
				});
				require(["../demo/modules/redirect.js"],function(js){
					js();
				})
			}
		</script>
	</body>
</html>
